<template>
  <div class="financial">
    <financial-nav></financial-nav>
    <financial-data :assets="assets"></financial-data>
    <financial-view :financialOrder="financialOrder"></financial-view>
  </div>
</template>

<script>
import financialNav from './child/financialNav.vue'
import financialData from './child/financialData.vue'
import financialView from './child/financialView.vue'
import {getSelfOrder} from '@/api/profile'
export default {
  data() {
    return {
      financialOrder:[],
      assets:{
        sum:0,
        yesIncome:0,
      },
    }
  },
  components: {
    financialNav,
    financialData,
    financialView
  },
  created(){
    this.getFinancialInfo()
  },
  methods:{
    getFinancialInfo(){
      getSelfOrder().then(res=>{
        if(res.data.list){
          let t = res.data.list
          let total=0;
          let reIncome=0;
          for(let i=0;i<t.length;i++){
            let obj = {}
            obj = t[i];
            let up = parseFloat(((t[i].product_interest_rate)*0.01 * t[i].product_price)/365).toFixed(2);
            let da = t[i].created_at.substring(0,10);
            let date1 = new Date(da);
            let date2 = new Date();
            let day = parseInt((date2 - date1) /(1*24*60*60*1000));
            if(day<1){
              obj.dayincome = 0;
            }else {
              obj.dayincome = up * day
            }
            obj.allIncome = day*up;
            this.financialOrder.push(obj);
            total += day*up;
            if(day<1){
              reIncome += 0;
            }else {
              reIncome += up*1.0;
            }
          }
          this.assets.sum = total
          this.assets.yesIncome = parseFloat(reIncome).toFixed(2) 
          }
        
      })
    }
  }
}
</script>

<style lang="less">

</style>